package com.rsk.api;



import javax.ws.rs.QueryParam;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.rsk.api.common.ReturnUtils;
import com.rsk.service.SysAuthorityService;
import com.rsk.utils.result.Result;

@RestController
@RequestMapping(value="/sys/auth")
public class SystemAuthorityApi {
	
	@Reference(interfaceClass = SysAuthorityService.class, protocol = "dubbo")
	private SysAuthorityService sysAuthorityService;
	
	
	//@RequiresPermissions("sys_users:save")
	@PostMapping(value="/saveSysAuthority" )
	public Result<String> saveSysAuthority(@QueryParam("authName") String authName,
		   							  	   @QueryParam("authCode") String authCode,
		   							  	   @QueryParam("menuId") Long menuId,
		   							  	   @RequestHeader("Authorization") String Authorization){
		//数据校验
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = sysAuthorityService.saveSysAuthority(authName, authCode, menuId, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
	//@RequiresPermissions("sys_users:update")
	@PostMapping(value="/updateSysAuthority" )
	public Result<String> updateSysAuthority(@QueryParam("id") Long id,
									   		 @QueryParam("authName") String authName,
									   		 @QueryParam("authCode") String authCode,
									   		 @RequestHeader("Authorization") String Authorization){
		//数据校验
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = sysAuthorityService.updateSysAuthority(id, authName, authCode, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
	
	
	//@RequiresPermissions("sys_users:del")
	@PostMapping(value="/delSysAuthority" )
	public Result<String> delSysAuthority(@QueryParam("id") Long id,
									 @RequestHeader("Authorization") String Authorization){
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = sysAuthorityService.delSysAuthority(id, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
}
